<template>
  <div class="search">
    <f-drawer ref="shopserverDrawer" :title="drawerTitle" width="60%" @submit="handleSubmit" @visibleChange="visibleChange">
      <a-tabs @tabClick="tabClick" :defaultActiveKey="current" v-model="current">
        <a-tab-pane tab="基本信息" key="form1">
           <shopserver-form ref="form1" v-if="drawerVisible"></shopserver-form>
        </a-tab-pane>
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>
  import shopserverForm from './shopserver_form.vue'
  export default {
    name: 'shopserverDrawer',
    props: {},
    data() {
      return {
        refs:this.$refs,
        drawerVisible: false,
        isEdit: false,
        title: '',
        current: 'form1',
        formData: {},
        forms: [
          'form1'
        ]
      }
    },
    methods: {
      showDrawer(data) {
        this.isEdit = false
        if (data && data.ssId) {
          this.isEdit = true
          this.formData = data
        } else {
          this.formData = {}
        }
        this.refs['shopserverDrawer'].show()
        this.tabClick('form1')
      },
      handleSubmit(callback) {
        this.refs[this.current].handleSubmit(callback)
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      tabClick(name) {
        this.current = name
        if (this.current === 'form1') {
          this.title = this.isEdit ? '编辑商家 --服务记录表' : '添加商家 --服务记录表'
        }
        this.$nextTick(() => {
          this.refs[this.current].setData(this.formData)
        })
      }
    },
    computed: {
      drawerTitle: function() {
        return this.title
      }
    },
    created() {
    },
    components: { shopserverForm }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
